package com.pagoda.nerp;

import com.pagoda.nerp.web.services.HRORGPostService;
import com.pagoda.nerp.web.services.HRUnitService;
import com.pagoda.nerp.web.services.HRZGZDService;
import com.pagoda.nerp.webapi.hander.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;

import static com.pagoda.nerp.erpgwehrApplication.posttree;
import static com.pagoda.nerp.erpgwehrApplication.unittree;
/**
 * @Author:HXB
 * @Description:
 * @Date create in 14:15 2018/1/16
 * @Modified By:
 */
@Component
public class TreeInitRunner implements CommandLineRunner {
    @Autowired
    private HRUnitService hrUnitService;
    @Autowired
    private HRORGPostService hrorgPostService;
    @Autowired
    private HRZGZDService hrzgzdService;
    @Value("${rootid}")
    private String rootid;

    public void updateData(){
        hrUnitService.updateDBUnit();
        hrorgPostService.updateDBPost();
        hrzgzdService.updateDBEmployee();
    }

    public ResponseResult getHRUnitTree(){
        return hrUnitService.getHRUnitTree(rootid);
    }

    public ResponseResult getHRPostTree(){
        return hrorgPostService.getHRORGPostTree(rootid);
    }

    @Override
    public void run (String args[]){
        updateData();

        unittree = getHRUnitTree();
        System.out.println("GetHRUnitTree Complete!"+unittree.toString().length());

        posttree = getHRPostTree();
        System.out.println("GetHRPostTree Complete!"+posttree.toString().length());

    }
}
